/**
 * 应用初始化.
 */
//初始化日志组件
appcan.ready(function() {
    initI18nConfig();
    initLogConfig();
    initMdbConfig();
    initAjaxConfig();
    
    //初始化应用信息
    try {
        Supp.MEIP.initWidgetAppInfo();
    } catch (e) { }
});

//多语言配置
function initI18nConfig() {
    Supp.I18N.cache(true);
    Supp.I18N.encoding("UTF-8");
    Supp.I18N.useRemote(true);
}

//日志配置
function initLogConfig() {
    //Supp.Log.level("DEBUG"); //设置为debug级别，一般在开发期间使用，级别最低
    // Supp.Log.level("INFO"); //设置为info级别，一般用于输出普通日志信息
    // Supp.Log.level("WARN"); //设置为warn级别，一般用于警告信息
    // Supp.Log.level("ERROR"); //设置为error级别，一般用于报错、异常信息
    // Supp.Log.level("NONE"); //关闭日志输出
    var log = Supp.Log.create("supp-cfg-init.js");
    log.init();
}

//初始化数据库
function initMdbConfig() {
    var dbName = "SuppMobile";
    
    var createTablesSQL = [
        //创建工作平台表
        "create table if not exists meip_desktop ("
            + "desktopId varchar(32), " //工作平台Id
            + "tenant varchar(30), " //租户、企业标识
            + "nameZh varchar(30), " //中文名称
            + "nameEn varchar(30), " //英文名
            + "name3 varchar(30), " //名称3
            + "name4 varchar(30), " //名称4
            + "displayOrder integer, " //排序字段
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_desktop primary key(desktopId))",
        
        //创建常用分组表
        "create table if not exists meip_com_oper_group ("
            + "groupId varchar(32), " //分组id
            + "nameZh varchar(30), " //中文名
            + "nameEn varchar(30), " //英文名
            + "name3 varchar(30), " //名称3
            + "name4 varchar(30), " //名称4
            + "displayOrder integer, " //排序字段
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_com_oper_group primary key(groupId))",
            
        //创建常用表
        "create table if not exists meip_com_oper ("
            + "desktopId varchar(32), "
            + "groupId varchar(32), "
            + "moduleId varchar(32), "
            + "comOperId varchar(32), " 
            + "nameZh varchar(30), "
            + "nameEn varchar(30), "
            + "name3 varchar(30), "
            + "name4 varchar(30), " 
            + "iconPath text, "
            + "page varchar(50), "
            + "params varchar(100), "
            + "displayOrder integer, "
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_com_oper primary key(desktopId, groupId, moduleId, comOperId))",
        
        //创建已安装应用表
        "create table if not exists meip_installed (" 
            + "moduleId varchar(32), "
            + "nameZh varchar(30), "
            + "nameEn varchar(30), "
            + "name3 varchar(30), "
            + "name4 varchar(30), " 
            + "version varchar(10), "
            + "meipVersion varchar(10), "
            + "size varchar(10), "
            + "iconPath text, " 
            + "introZh text, "
            + "introEn text, "
            + "intro3 text, "
            + "intro4 text, "
            + "addDate integer, "
            + "status char(1), "
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_installed primary key(moduleId))",
            
        //创建应用导航表
        "create table if not exists meip_appnav ("
            + "appnavId VARCHAR(32), " //应用导航Id
            + "desktopId VARCHAR(32), " //工作平台Id
            + "nameZh VARCHAR(20), " //中文名称
            + "nameEn VARCHAR(20), " //英文名称
            + "name3 VARCHAR(20), " //名称3
            + "name4 VARCHAR(20), " //名称4
            + "moduleId VARCHAR(12), " //应用编号
            + "iconPath text, " //图标地址
            + "page VARCHAR(100), " //打开页面地址
            + "isShow CHAR(1), " //是否显示 T显示 F不显示
            + "displayOrder INTEGER, " //显示顺序
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_appnav primary key(desktopId,appnavId))",
            
        //创建卡片表
        "create table if not exists meip_widget ("
            + "widgetId varchar(32), " //卡片Id
            + "desktopId VARCHAR(32), " //工作平台Id
            + "nameZh VARCHAR(30), " //中文名称
            + "nameEn VARCHAR(30), " //英文名称
            + "name3 VARCHAR(30), " //名称3
            + "name4 VARCHAR(30), " //名称4
            + "moduleId VARCHAR(12), " //应用编号
            + "isWidget CHAR(1), " //是否卡片 T是 F否
            + "iconPath text, " //图片路径
            + "url VARCHAR(100), " //卡片内容服务地址
            + "isShow char(1), " //是否显示 T是 F否
            + "displayOrder INTEGER, " //显示顺序
            + "action text, " //操作按钮 
            + "updateTime datetime, " //更新时间
            + "displayStyle CHAR(1), " //显示样式 1带标题栏 2不带标题栏
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_widget primary key(desktopId,widgetId))",
            
        //创建我的表
        "create table if not exists meip_my ("
            + "myId VARCHAR(32), " //我的Id
            + "moduleId VARCHAR(12), " //应用编号
            + "nameZh VARCHAR(30), " //中文名称
            + "nameEn VARCHAR(30), " //英文名称
            + "name3 VARCHAR(30), " //名称3
            + "name4 VARCHAR(30), " //名称4
            + "iconPath text, " //图片地址
            + "page VARCHAR(100), " //页面地址
            + "systemPreset CHAR(1), " //是否预置 T是 F否
            + "displayOrder INTEGER, " //显示顺序   
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_my primary key(myId))", 
            
        //创建设置表
        "create table if not exists meip_setting ("
            + "settingId VARCHAR(32), " //设置Id
            + "desktopId VARCHAR(32), " //工作平台Id
            + "moduleId VARCHAR(12), " //应用编号
            + "nameZh VARCHAR(30), " //中文名称
            + "nameEn VARCHAR(30), " //英文名称
            + "name3 VARCHAR(30), " //名称3
            + "name4 VARCHAR(30), " //名称4
            + "iconPath text, " //图片地址
            + "page VARCHAR(100), " //页面地址
            + "displayOrder INTEGER, " //显示顺序   
            + "ext1 varchar(50), " //扩展字段1
            + "ext2 varchar(50), " //扩展字段2
            + "ext3 varchar(50), " //扩展字段3
            + "ext4 varchar(50), " //扩展字段4
            + "ext5 varchar(50), " //扩展字段5
            + "constraint pk_setting primary key(desktopId,settingId))",
            
        //创建聊天表
        "create table if not exists meip_chat("
            + "chatId VARCHAR(32), " //聊天Id
            + "fromId VARCHAR(30), " //发送人Id
            + "fromName VARCHAR(30), " //发送人姓名
            + "toId VARCHAR(30), " //接收人
            + "toName VARCHAR(30), " //接收人姓名
            + "roomId VARCHAR(30), " //聊天室id
            + "chatType VARCHAR(10), " //聊天类型
            + "msg VARCHAR(500), " //消息内容
            + "isRead CHAR(1), " //是否已读,T已读，F未读
            + "isMUC CHAR(1), " //是否群聊,T群聊，F单聊
            + "inTime datetime, " //发送、接收时间
            + "constraint pk_chat primary key(chatId))"
    ];
    
    var dbHelper = Supp.MDB.create(dbName, createTablesSQL);
}

//ajax配置
function initAjaxConfig() {
    Supp.Ajax.useRemoteServer(true);
}
